From 0d038a9075a30d676ee7066b8bfaeb1ca584278f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 2 Nov 2016 10:32:35 -0700 Subject: [PATCH] Default urls in [replace] to crates.io The intention was to do this, and it mistakenly didn't happen! Closes #3235 --- src/cargo/core/package_id_spec.rs | 4 +++ src/cargo/util/toml.rs | 6 +++- tests/overrides.rs | 56 +++++++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/package_id_spec.rs b/src/cargo/core/package_id_spec.rs index 3299ada57..a07b69e49 100644 --- a/src/cargo/core/package_id_spec.rs +++ b/src/cargo/core/package_id_spec.rs @@ -110,6 +110,10 @@ impl PackageIdSpec { pub fn version(&self) -> Option<&Version> { self.version.as_ref() } pub fn url(&self) -> Option<&Url> { self.url.as_ref() } + pub fn set_url(&mut self, url: Url) { + self.url = Some(url); + } + pub fn matches(&self, package_id: &PackageId) -> bool { if self.name() != package_id.name() { return false } diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index bc72b5ee9..dc5f92870 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -15,6 +15,7 @@ use core::{EitherManifest, VirtualManifest}; use core::dependency::{Kind, Platform}; use core::manifest::{LibKind, Profile, ManifestMetadata}; use core::package_id::Metadata; +use sources::CRATES_IO; use util::{self, CargoResult, human, ToUrl, ToSemver, ChainError, Config}; /// Representation of the projects file layout. @@ -740,11 +741,14 @@ impl TomlManifest { -> CargoResult> { let mut replace = Vec::new(); for (spec, replacement) in self.replace.iter().flat_map(|x| x) { - let spec = try!(PackageIdSpec::parse(spec).chain_error(|| { + let mut spec = try!(PackageIdSpec::parse(spec).chain_error(|| { human(format!("replacements must specify a valid semver \ version to replace, but `{}` does not", spec)) })); + if spec.url().is_none() { + spec.set_url(CRATES_IO.parse().unwrap()); + } let version_specified = match *replacement { TomlDependency::Detailed(ref d) => d.version.is_some(), diff --git a/tests/overrides.rs b/tests/overrides.rs index c7d56799f..ba17e0f32 100644 --- a/tests/overrides.rs +++ b/tests/overrides.rs @@ -73,7 +73,7 @@ fn missing_version() { error: failed to parse manifest at `[..]` Caused by: - replacements must specify a version to replace, but `foo` does not + replacements must specify a version to replace, but `[..]foo` does not ")); } @@ -468,7 +468,7 @@ fn override_wrong_name() { execs().with_status(101).with_stderr("\ [UPDATING] registry [..] [UPDATING] git repository [..] -error: no matching package for override `foo:0.1.0` found +error: no matching package for override `[..]foo:0.1.0` found location searched: file://[..] version required: = 0.1.0 ")); @@ -530,7 +530,7 @@ fn override_wrong_version() { error: failed to parse manifest at `[..]` Caused by: - replacements cannot specify a version requirement, but found one for `foo:0.1.0` + replacements cannot specify a version requirement, but found one for `[..]foo:0.1.0` ")); } @@ -875,3 +875,53 @@ fn override_an_override() { assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0)); } + +#[test] +fn overriding_nonexistent_no_spurious() { + Package::new("foo", "0.1.0").dep("bar", "0.1").publish(); + Package::new("bar", "0.1.0").publish(); + + let foo = git::repo(&paths::root().join("override")) + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + + [dependencies] + bar = { path = "bar" } + "#) + .file("src/lib.rs", "pub fn foo() {}") + .file("bar/Cargo.toml", r#" + [package] + name = "bar" + version = "0.1.0" + authors = [] + "#) + .file("bar/src/lib.rs", "pub fn foo() {}"); + foo.build(); + + + let p = project("local") + .file("Cargo.toml", &format!(r#" + [package] + name = "local" + version = "0.0.1" + authors = [] + + [dependencies] + foo = "0.1.0" + + [replace] + "foo:0.1.0" = {{ git = '{url}' }} + "bar:0.1.0" = {{ git = '{url}' }} + "#, url = foo.url())) + .file("src/lib.rs", ""); + + assert_that(p.cargo_process("build"), + execs().with_status(0)); + assert_that(p.cargo("build"), + execs().with_status(0).with_stderr("\ +[FINISHED] [..] +").with_stdout("")); +} -- 2.30.2